home *** CD-ROM | disk | FTP | other *** search
- /* Listing 8*/
- /***********************************************************
- Testlist.c - Program to test the list object using a phone
- list as an example.
- ***********************************************************/
- #include "phlist2.h"
-
- static PHONE_ENTRY test_data[] = {
- {"Able","Ben","456-7890"},{"Smith","John","456-0987"},
- {"Kirk","Jim","622-1701"},{"Picard","Jon L.","622-1701"},
- {"Jones","Cyrano","874-2253"}
- };
-
- static PHONE_ENTRY jane = {"Smith","Jane","123/456-0987"};
-
- main()
- {
- PHONE_LIST *pe;
- int x;
-
- pe = new_phone_list();
- for (x = 0; x < 5; ++x)
- pe->add_member(pe,&test_data[x]);
- printf("\nTesting Phone List:\n");
- pe->top(pe);
-
- while( ! pe->at_end(pe) ) {
- pe->display(pe); pe->next(pe);
- }
- printf("\n Finding - Kirk \n");
- pe->top(pe);
- if (pe->find(pe,"Kirk") == TRUE)
- pe->display(pe);
- printf("\n Trying to find McCoy \n");
- if (pe->find(pe,"McCoy") == FALSE)
- printf("\nMcCoy not found\n");
- printf("Current Member is :\n");
- pe->display(pe);
- printf("Replace John Smith with Jane\n");
- pe->top(pe);
- if (pe->find(pe,"Smith") == TRUE) {
- pe->replace_member(pe,&jane);
- }
- else {
- printf("Not Found (Strike a Key)\n"); getch();
- }
- printf("\nRedisplaying phone list:\n");
- pe->top(pe);
- while( ! pe->at_end(pe) ) {
- pe->display(pe); pe->next(pe);
- }
- pe->end(pe);
- printf("Total members = %ld\n",pe->total_members(pe));
- printf("Current member = %ld\n",pe->tell(pe));
- }
-